using System.Collections.Generic;
using XLua;
using Yoozoo.Framework.Managers;

namespace Gameplay.PVE
{
    public class PveLuaManager
    {
        private static PveLuaManager m_instance;

        public static PveLuaManager Instance
        {
            get
            {
                if (m_instance == null)
                {
                    m_instance = new PveLuaManager();
                }
                return m_instance;
            }
        }
        
        private Dictionary<string,LuaFunction> functions = new Dictionary<string,LuaFunction>();
        
        public object[] CallFunction(string functionName,params object[] args)
        {
            return GetFunction(functionName).Call(args);
        }

        public LuaFunction GetFunction(string functionName)
        {
            LuaFunction function;
            if (!functions.TryGetValue(functionName, out function))
            {
                function = LuaManager.mainState.GetFunction(functionName);
                functions.Add(functionName,function);
            }
            return function;
        }
    }
}